//
//  SISSCalculationResultCell.m
//  SISSAPP
//
//  Created by 优房网 on 2017/8/16.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSCalculationResultCell.h"

@interface SISSCalculationResultCell ()

/* 期数Label */
@property (weak, nonatomic) UILabel *periodLabel;
/* 本金Label */
@property (weak, nonatomic) UILabel *principalLabel;
/* 利息Label */
@property (weak, nonatomic) UILabel *interestLabel;
/* 月供Label */
@property (weak, nonatomic) UILabel *monthlyPaymentLabel;
/* 底部线 */
@property (weak, nonatomic) UIView *bottomLine;

@end
@implementation SISSCalculationResultCell

- (void)setDict:(NSDictionary *)dict {
    _dict = dict;
    
    self.periodLabel.text = dict[@"period"];
    self.principalLabel.text = dict[@"principal"];
    self.interestLabel.text = dict[@"interest"];
    self.monthlyPaymentLabel.text = dict[@"monthlyPayment"];
}

#pragma mark - UI
- (void)initUI {
    [super initUI];
    
    UILabel *periodLabel = [[UILabel alloc] init];
    periodLabel.textColor = COLOR(0x334A60);
    periodLabel.font = [UIFont systemFontOfSize:16];
    [self.contentView addSubview:periodLabel];
    self.periodLabel = periodLabel;
    
    UILabel *principalLabel = [[UILabel alloc] init];
    principalLabel.textColor = COLOR(0x334A60);
    principalLabel.font = [UIFont systemFontOfSize:16];
    [self.contentView addSubview:principalLabel];
    self.principalLabel = principalLabel;
    
    UILabel *interestLabel = [[UILabel alloc] init];
    interestLabel.textColor = COLOR(0x334A60);
    interestLabel.font = [UIFont systemFontOfSize:16];
    [self.contentView addSubview:interestLabel];
    self.interestLabel = interestLabel;
    
    UILabel *monthlyPaymentLabel = [[UILabel alloc] init];
    monthlyPaymentLabel.textColor = COLOR(0x334A60);
    monthlyPaymentLabel.font = [UIFont systemFontOfSize:16];
    [self.contentView addSubview:monthlyPaymentLabel];
    self.monthlyPaymentLabel = monthlyPaymentLabel;
    
    UIView *bottomLine = [[UIView alloc] init];
    bottomLine.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.contentView addSubview:bottomLine];
    self.bottomLine = bottomLine;
}

#pragma mark - 约束
- (void)initConstraint {
    [super initConstraint];
    
    CGFloat margin = 8.0;
    WeakSelf
    [self.periodLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.contentView).offset(2 * margin);
        make.top.equalTo(weakSelf.contentView).offset(1.5 * margin);
    }];
    
    [self.principalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(weakSelf.periodLabel);
        if (SCREEN_WIDTH > 320) {
             make.left.equalTo(weakSelf.contentView).offset(11 * margin);
        } else {
             make.left.equalTo(weakSelf.contentView).offset(10 * margin);
        }
    }];
    
    [self.interestLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(weakSelf.periodLabel);
        if (SCREEN_WIDTH > 320) {
            make.left.equalTo(weakSelf.contentView.mas_centerX).offset(-2 * margin);
        } else {
            make.left.equalTo(weakSelf.contentView.mas_centerX);
        }
    }];
    
    [self.monthlyPaymentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.contentView.mas_centerX).offset(11 * margin);
        make.centerY.equalTo(weakSelf.periodLabel);
    }];
    
    [self.bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(weakSelf.contentView);
        make.height.mas_equalTo(1);
        make.top.equalTo(weakSelf.periodLabel.mas_bottom).offset(1.5 * margin);
    }];
}

@end
